///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef __BUOLA_THREADS_THREAD_H__
#define __BUOLA_THREADS_THREAD_H__

#include <buola/buola.h>

#if 0//BUOLA_COMPILER_CLANG
  #include <boost/thread/thread.hpp>
#else
  #include <thread>
#endif

namespace buola {

#if 0//BUOLA_COMPILER_CLANG
  using boost::thread;
#else
  using std::thread;
#endif
    
namespace detail {
    
    template<typename tFunc>
    class AInThread
    {
    public:
        AInThread(const tFunc &pFunc)
            :   mFunc(pFunc)
        {}
        
        template<typename... tArgs>
        void operator()(tArgs&&... pArgs) const
        {
            thread lThread(std::bind(mFunc,std::forward<tArgs>(pArgs)...));
            lThread.detach();
        }
        
    private:
        tFunc mFunc;
    };
    
/*namespace detail*/ }

template<typename tFunc>
detail::AInThread<tFunc> in_thread(const tFunc &pFunc)
{
    return detail::AInThread<tFunc>(pFunc);
}

/*namespace buola*/ }

#endif
